package com.peng.leetcode.other;

/**
 * NumReverse
 *
 * @author: lupeng6
 * @create: 2020/10/16 17:10
 */
public class NumReverse {

    public static void main(String[] args) {
//        System.out.println(Integer.MIN_VALUE);
//        System.out.println(Integer.MAX_VALUE);
        System.out.println(new Solution().reverse(1534236469));
    }

    static class Solution {
        public int reverse(int num) {
            int ret = 0;
            while (num != 0) {
                int pop = num % 10;
                if (ret > Integer.MAX_VALUE / 10 || (ret == Integer.MAX_VALUE / 10 && pop > 7)) {
                    return 0;
                }
                if (ret < Integer.MIN_VALUE / 10 || (ret == Integer.MIN_VALUE / 10 && pop < -8)) {
                    return 0;
                }
                ret = ret * 10 + pop;
                num = num / 10;
            }
            return ret;
        }
    }
}
